/******************************************************************************
 * SAGE - Scalable Adaptive Graphics Environment
 *
 * Module: fsManager.h
 * Author : Byungil Jeong
 *
 * Copyright (C) 2004 Electronic Visualization Laboratory,
 * University of Illinois at Chicago
 *
 * This library is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either Version 2.1 of the License, or
 * (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
 * License for more details.
 *
 * You should have received a copy of the GNU Lesser Public License along
 * with this library; if not, write to the Free Software Foundation, Inc.,
 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
 *
 * Direct questions, comments etc about SAGE to bijeong@evl.uic.edu or 
 * http://www.evl.uic.edu/cavern/forum/
 *
 *****************************************************************************/
 

#ifndef _FSManager_H
#define _FSManager_H

#include "sage.h"
#include <QUANTA/QUANTA.hxx>

class fsCore;
class displayManager;
class fsServer;
class sageVirtualDesktop;

class rcvInfo {
public:
	int syncPort;
	int streamPort;
	int bufSize;
	bool fullScreen;
	
        bool audioOn;
        int audioPort;
        int audioSyncPort;
        int agSyncPort;

	rcvInfo() : syncPort(11000), streamPort(21000), bufSize(64), fullScreen(true), audioOn(false), audioSyncPort(13000), audioPort(23000), agSyncPort(15000) {}
};	

class sageNwConfig;

class fsManager {
private:
	fsCore *core;
	fsServer *server;
	sageVirtualDesktop *vdt;
	rcvInfo rInfo;
	sageNwConfig *nwInfo;
	std::vector<appInExec *> execList;
	std::vector<displayManager *> dispList;
	std::vector<int> uiList;
	std::vector<int> appUiList;
	std::vector<sageRect *> drawObjectList;

	char fsIP[SAGE_IP_LEN];
	char pubIP[SAGE_IP_LEN];
	char fsName[SAGE_NAME_LEN];
	char conManIP[SAGE_IP_LEN];
	int conManPort;
	int uiPort, sysPort, trackPort;
	int winTime;	
	int winStep;
	bool NRM;
	bool blockCommands;
	bool fsmClose;
	
	static void* msgThread(void *args);
	int talkToConnectionManager();
	
public:
   fsManager();
   ~fsManager();
   int init(char *config); 
	void printAppList();
	char* getFsIP() { return fsIP; }
	int getUiPort() { return uiPort; }
	int getSysPort() { return sysPort; }	
	int getTrackPort() { return trackPort; }
	void mainLoop();
	int msgToCore(sageMessage &msg, int clientID);
	int msgToDisp(sageMessage &msg, int clientID);
	int sendMessage(int cId, int code, int data);
	int sendMessage(int cId, int code, char* data);
	int sendMessage(int cId, int code);	
	int sendMessage(sageMessage &msg);
	int windowChanged(int appId);
	
	friend class fsCore;
	friend class displayManager;
	friend class fsServer;
};

#endif
